package com.spit.fammo.bean

import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import com.spit.amoeba.bean.dao.UploadOrderDao
import com.spit.amoeba.bean.dao.UploadOrderListDao
import com.spit.amoeba.bean.db.UploadOrderBean
import com.spit.amoeba.bean.db.UploadOrderListBean
import com.spit.fammo.bean.dao.AssetDao
import com.spit.fammo.bean.db.AssetBean
import com.spit.fammo.bean.db.ListingBean
import com.spit.fammo.bean.db.StockTakeListBean
import com.spit.hkpost.bean.dao.ConfigDao
import com.spit.hkpost.bean.db.ConfigBean
import com.spit.fammo.mar.MyApplication
import com.spit.hkpost.bean.dao.ListingDao
import com.spit.hkpost.bean.dao.StockTakeListDao


/**
 * @Author nike
 * @Date 2023/7/11 18:00
 * @Description
 */
@Database(entities = [
    ConfigBean::class,
    AssetBean::class,
    ListingBean::class,
    StockTakeListBean::class,
    UploadOrderBean::class,
    UploadOrderListBean::class,
], version = 1, exportSchema = false)
abstract class AppRoomDataBase : RoomDatabase() {

    abstract fun getConfigDao(): ConfigDao

    abstract fun getAssetDao(): AssetDao

    abstract fun getListingDao(): ListingDao

    abstract fun getStockTakeListDao(): StockTakeListDao

    abstract fun getUploadOrderDao(): UploadOrderDao

    abstract fun getUploadOrderListDao(): UploadOrderListDao

    companion object {

        @Volatile
        private var databaseInstance: AppRoomDataBase? = null

        @Synchronized
        @JvmStatic
        fun get(): AppRoomDataBase {
            if (databaseInstance == null) {
                databaseInstance = Room.databaseBuilder(
                    MyApplication.get(),
                    AppRoomDataBase::class.java,
                    "FAMMO.db"
                )
                    .build()
            }
            return databaseInstance!!
        }

    }

}